home *** CD-ROM | disk | FTP | other *** search
Text File | 1985-12-08 | 6.4 KB | 326 lines | [TEXT/RCMP] |
- program TellTime;
- Link __IO, __Uniform ,__Extendio, __Strings, __Quickdraw,
- __Sane, __saneio, __Printlib :;
- Var
-
- len,i,r:integer;
- irect,digrect:block[8];
- irectptr,digrptr:ptrw;
- x,y:integer;
- height,width,size:integer;
- xminhand,yminhand,xhrhand,yhrhand,handtype:integer;
- xhr,yhr,xmin,ymin:integer;
- xminold,yminold,xhrold,yhrold:integer;
- arctan,c15708,c47116,c62832:float;
- dighour,digmin:integer;
-
- procedure _INIT();
-
- begin
- setorigin(0,0);
- digrptr:=digrect;
- digrptr^:=90;
- digrptr:=digrptr+2;digrptr^:=300;
- digrptr:=digrptr+2;digrptr^:=150;
- digrptr:=digrptr+2;digrptr^:=490;
- i:=0;
- xminhand:=0;
- xhrhand:=0;
- yminhand:=0;
- yhrhand:=0;
- handtype:=1;
- xminold:=130;
- yminold:=130;
- xhrold:=130;
- yhrold:=130;
- dighour:=0;
- digmin:=0;
- iqfillf(15708,-4,c15708);
- iqfillf(3,0,c47116);
- mulf(@c15708,@c47116);
- iqfillf(4,0,c62832);
- mulf(c15708,c62832);
- ClockFace();
-
- end;
-
- Procedure _MAIN();
- begin
- (* *)
- end;
-
- Procedure _Mouse(x,y:integer);
- Var
- xf,yf,rf:float;
- xi,yi:integer;
- xr,yr,con:integer;
- xsave,ysave,rconst:float;
- rmin,rhr:float;
- begin
- textsize(12);
- moveto(300,10);
- (* writeint(x);
- writeint(y); *)
- x:=x-130;
- y:=y-130;
- iqfillf(x,0,xf);
- iqfillf(y,0,yf);
- ftof(xf,xsave);
- ftof(yf,ysave);
- (* compute arctan *)
- ftof(@ysave,@arctan);
- if x=0
- then
- begin
- iqfillf(15708,-4,arctan);
- end
- else
- begin
- divf(@xsave,@arctan);
- atanf(@arctan);
- end;
- (* moveto(280,80);
- writef(arctan); *)
- if x<0
- then
- begin
- addf(@c47116,@arctan);
- end
- else
- begin
- addf(@c15708,@arctan);
- end;
- (* moveto(280,100);
- writef(arctan); *)
- (* end computation *)
- mulf(@xf,@xf);
- mulf(@yf,@yf);
- addf(@yf,@xf);
- iqfillf(0,0,rf);
- addf(@xf,@rf);
- sqrtf(@rf);
- ftoi(@rf,@r);
- moveto(300,20);
- (* writeint(r); *)
- (* xr yr are coordinates of normalized r *)
- itof(60,rconst);
-
- ftof(xsave,xf);
- mulf(@rconst,@xf);
- divf(@rf,@xf);
- ftoi(@xf,@xi);
-
- (* moveto(300,30);
- writeint(xi); *)
- ftof(ysave,yf);
- mulf(@rconst,@yf);
- divf(@rf,@yf);
- ftoi(@yf,@yi);
- (* writeint(yi); *)
- itof(45,rhr);
- ftof(xsave,xf);
- mulf(@rhr,@xf);
- divf(@rf,@xf);
- ftoi(@xf,@xhr);
- moveto(300,40);
- (* writeint(xhr); *)
- ftof(ysave,yf);
- mulf(@rhr,@yf);
- divf(@rf,@yf);
- ftoi(@yf,@yhr);
- (* writeint(yhr); *)
- itof(75,rmin);
- ftof(xsave,xf);
- mulf(@rmin,@xf);
- divf(@rf,@xf);
- ftoi(@xf,@xmin);
- (* moveto(300,50);
- writeint(xmin); *)
- ftof(ysave,yf);
- mulf(@rmin,@yf);
- divf(@rf,@yf);
- ftoi(@yf,@ymin);
- (* writeint(ymin); *)
-
- if handtype=0
- then
- begin
- hourhand();
- getimeh();
- end
- else
- begin
- minhand();
- getimem();
- end;
- (* moveto(300,120);writeint(dighour);writeint(digmin); *)
- digital();
- end;
- procedure hourhand();
- var newx,newy:integer;
- begin
- moveto(300,10);
- writestring("Hour Hand ");
- handtype:=1;
- pensize(5,5);
- erasehr();
- moveto(130,130);
- newx:=xhr+130;
- newy:=yhr+130;
- lineto(newx,newy);
- xhrold:=newx;
- yhrold:=newy;
- end;
- procedure erasehr();
- begin
- moveto(130,130);
- penmode(11);
- lineto(xhrold,yhrold);
- penmode(8);
- pensize(3,3);
- moveto(130,130);
- lineto(xminold,yminold);
- pensize(5,5);
- end;
- procedure minhand();
- var newx,newy:integer;
- begin
- moveto(300,10);
- writestring("Minute hand");
- handtype:=0;
- pensize(3,3);
- erasemin();
- moveto(130,130);
- newx:=xmin+130;
- newy:=ymin+130;
- lineto(newx,newy);
- xminold:=newx;
- yminold:=newy;
- end;
- procedure erasemin();
- begin
- moveto(130,130);
- penmode(11);
- lineto(xminold,yminold);
- penmode(8);
- pensize(5,5);
- moveto(130,130);
- lineto(xhrold,yhrold);
- pensize(3,3);
- end;
-
- Procedure Tickmark();
- Var h1,v1,h2,v2:integer;
- Begin
- h1:=110;v1:=0; h2:=120;v2:=0; drawtick(h1,v1,h2,v2);
- h1:=55; v1:=95; h2:=60; v2:=104;drawtick(h1,v1,h2,v2);
- h1:=95; v1:=55; h2:=104;v2:=60; drawtick(h1,v1,h2,v2);
- h1:=0; v1:=110;h2:=0; v2:=120;drawtick(h1,v1,h2,v2);
- pensize(1,1);
- (* h1:=110;v1:=11;h2:=119;v2:=12;drawtick(h1,v1,h2,v2); *)
- End;
- Procedure drawtick(h1,v1,h2,v2:integer);
- Var ha,va,hb,vb:integer;
- Begin
- ha:=h1+130;va:=130-v1;hb:=h2+130;vb:=130-v2;
- moveto(ha,va);
- lineto(hb,vb);
- ha:=130-h1;
- hb:=130-h2;
- moveto(ha,va);
- lineto(hb,vb);
- va:=130+v1;
- vb:=130+v2;
- moveto(ha,va);
- lineto(hb,vb);
- ha:=130+h1;
- hb:=130+h2;
- moveto(ha,va);
- lineto(hb,vb);
-
- End;
- Procedure digital();
- Var hrstr,minstr,timestr,tempstr:block[100];
- longhr,longmin:longint;
- colonptr,zeroptr:ptrb;
- Begin
- timestring();
- moveto(260,200);
- textsize(36);
- eraserect(@digrect);
- moveto(320,140);
- longhr:=dighour;
- numtostr(longhr,hrstr);
- colonptr:=":";
- strncat(@hrstr,colonptr,2);
- longmin:=digmin;
- numtostr(longmin,minstr);
- if digmin<10
- then
- Begin
- zeroptr:="0";
- strcpy(@tempstr,@minstr);
- strcpy(@minstr,zeroptr);
- strncat(@minstr,@tempstr,4);
- End;
- strncat(@hrstr,@minstr,4);
- writestring(@hrstr);
- textsize(12);
- End;
- Procedure getimeh();
- Var ratio,fhour,fmin:float;
- Begin
- ftof(@arctan,@ratio);
- divf(@c62832,@ratio);
- (* moveto(280,120);
- writef(ratio); *)
- itof(12,fhour);
- mulf(@ratio,@fhour);
- trncintf(@fhour);
- (* moveto(280,140);
- writef(fhour); *)
- ftoi(@fhour,@dighour);
- if dighour=0 then dighour:=12;
- End;
- Procedure getimem();
- Var ratio,fhour,fmin:float;
- Begin
- ftof(@arctan,@ratio);
- divf(@c62832,@ratio);
- itof(60,fmin);
- mulf(@ratio,@fmin);
- trncintf(@fmin);
- ftoi(@fmin,@digmin);
- End;
- Procedure timestring();
- Begin
- End;
-
- Procedure ClockFace();
- begin
- irectptr:=irect;
- irectptr^:=10;
- irectptr:=irectptr+2;
- irectptr^:=10;
- irectptr:=irectptr+2;
- irectptr^:=250;
- irectptr:=irectptr+2;
- irectptr^:=250;
- pensize(2,2);
- frameoval(@irect);
- size:=18; textsize(size);
- moveto(118,36); writestring("12");
- moveto(125,235); writestring("6");
- moveto(227,137); writestring("3");
- moveto(24,138); writestring("9");
- moveto(173,52);writestring("1");
- moveto(74,57);writestring("11");
- moveto(75,218);writestring("7");
- moveto(171,219);writestring("5");
- moveto(203,86);writestring("2");
- moveto(42,86);writestring("10");
- moveto(42,188);writestring("8");
- moveto(207,187);writestring("4");
- Tickmark();
-
- end;